/**
 * 
 * @author Eric Muehlberg
 *
 */


public class player
{
	WObject obj;
	boolean moveleft, moveright;
	boolean bump;
	boolean canjump, jumping;
	float Dy, Dx;
	
	/**
	 * 
	 * @param o Object used to represent player
	 * 
	 * <Make sure the d component of the object is 0 as the player should be 2D>
	 */
	public player(WObject o)
	{
		obj = o;
		moveleft = false;
		moveright = false;
		canjump = true;
		jumping = false;
		Dy = 0;
		Dx = 6.5f;
	}
	
	
	//updates using moveleft and moveright booleans
	// needs to be modified to include jumping
	public void update(long time)
	{
		float Hspeed = Dx * time/1000.f;
		
		if(moveleft)
		{
			
			switch(obj.getO())
			{
			case xAxis:
				updateX(-Hspeed);
				break;
			case nxAxis:
				updateX(Hspeed);
				break;
			case zAxis:
				updateX(Hspeed);
				break;
			case nzAxis:
				updateX(-Hspeed);
				break;
			}
			
		}
		else if(moveright)
		{
			switch(obj.getO())
			{
			case xAxis:
				updateX(Hspeed);
				break;
			case nxAxis:
				updateX(-Hspeed);
				break;
			case zAxis:
				updateX(-Hspeed);
				break;
			case nzAxis:
				updateX(Hspeed);
				break;
			}
		}
		
		if(jumping)
		{
			Dy = 10;
			jumping = false;
		}
		
		updateY(Dy * (time/1000f));
		
		if(Dy > -10)
		{
			Dy = Dy - (10 * (time/1000f));
		}
		
		if(Dy < -1)
		{
			canjump = false;
		}
	}
	
	public void Jump()
	{
		if(canjump)
		{
			jumping = true;
			canjump = false;
		}
	}
	
	/**
	 * Changes the characters orientation to the respective plane
	 * via a 90 degree rotation of the level to the left.
	 */
	public void snapLeft()
	{
		((Cube)obj).snapleft();
	}
	
	/**
	 * Changes the characters orientation to the respective plane
	 * via a 90 degree rotation of the level to the right.
	 */
	public void snapRight()
	{
		((Cube)obj).snapright();
	}

//Use the following in the future once perspective shift has been fully configured.

	/**
	 * Returns the relative x coordinate based on perspective
	 * 
	 * Returns x if in one of the X-axis orientations
	 * Returns z if in one of the Z-axis orientations
	 * Else returns 0
	 * 
	 * <Do not assume 0 implies an error>
	 */
	public float getX()
	{
		return obj.getX();
	}
	
	public float getRX()
	{
		return obj.getRX();
	}
	
	public float getY()
	{
		return obj.getY();
	}
	
	public float getZ()
	{
		return obj.getZ();
	}
	
	public float getW()
	{
		return obj.getW();
	}
	
	public float getRW()
	{
		return obj.getRW();
	}
	
	public float getH()
	{
		return obj.getH();
	}
	
	public float getD()
	{
		return obj.getD();
	}
	/**
	 * Updates the relative x coordinate based on perspective
	 * 
	 * Updates x if in one of the X-axis orientations
	 * Updates z if in one of the Z-axis orientations
	 */
	public void updateX(float x)
	{
		obj.updateX(x);
	}
	
	public void updateY(float y)
	{
		obj.updateY(y);
	}
	
	public void updateDY(float dy)
	{
		Dy = dy;
	}
	
	public void updateDX(float dx)
	{
		Dx = dx;
	}
	
	public float getRZ()
	{
		return obj.getRZ();
	}
	
	public void updateRZ(float z)
	{
		obj.updateRZ(z);
	}
	
	public void yCollAdjust(float y)
	{
		if(y != -1000)
			obj.yCollAdjust(y);
	}
	
	public void xCollAdjust(float x)
	{
		if(x != -1000)
			obj.xCollAdjust(x);
	}
	
	public void ZBump(float RZ)
	{
		if(RZ != -1000)
		{
			updateRZ(RZ);
		}
	}
	
	public void Respawn(WObject strt)
	{
		obj.pos.x = strt.pos.x;
		obj.pos.y = strt.pos.y;
		obj.pos.z = strt.pos.z;
	}
}